﻿#include<iostream>
#include <queue>
#include <stack>
using namespace std;

//思路：
//参考：http://www.cnblogs.com/wanghui9072229/archive/2011/11/22/2259391.html

template<class T> class Que
{
public:
	void push(T t)
	{
		s1.push(t);
	}
	void pop()
	{
		if(s1.empty()&&s2.empty())
			cerr<<"is empty"<<endl;
		else if(s2.empty())
		{
			while(!s1.empty())
			{
				s2.push(s1.top());
				s1.pop();
			}
			s2.pop();
		}
		else
		{
			s2.pop();
		}
	}
	T front()
	{
		if(s1.empty()&&s2.empty())
			cerr<<"is empty"<<endl;
		else if(s2.empty())
		{
			while(!s1.empty())
			{
				s2.push(s1.top());
				s1.pop();
			}
			return s2.top();
		}
		else return s2.top();
	}
	
private:stack<T> s1,s2; 
};


void main()
{
	Que<int> q;
	q.push(1);
	q.push(2);
	q.push(3);
	cout<<q.front()<<endl;
	q.pop();
	cout<<q.front()<<endl;
	q.push(4);
	q.push(5);
	cout<<q.front()<<endl;
	q.pop();
	cout<<q.front()<<endl;
	q.pop();
	q.pop();
	q.pop();
	q.pop();


	queue<int> qq;
	qq.push(1);
	qq.push(2);
	qq.push(3);
	cout<<qq.front()<<endl;
	qq.pop();
	cout<<qq.front()<<endl;
	qq.push(4);
	qq.push(5);
	cout<<qq.front()<<endl;
	qq.pop();
	cout<<qq.front()<<endl;
	

}